#ifndef LIBLOADER_H
#define LIBLOADER_H

#include <QString>
#include <QMultiHash>
#include <QFile>
#include <QDomDocument>
#include <QCoreApplication>
#include "metaclass.h"

#define SCN_LIB       "lib"
#define SCN_CLASSES   "classes"
#define TAG_CLASS     "class"
#define ATTR_CL_NAME  "name"
#define ATTR_LIB_PATH "path"

class LibLoader : public QObject
{
    Q_OBJECT
public:
    ~LibLoader();

    static LibLoader* getInstance();
    MetaClass const * getClass(const QString& className, const QString& libName = "") const;
    QObject * getClassInstance(const QString& className, const QString& libName = "") const;

public slots:
    void loadLib(const QString& libName);

private:
    static LibLoader* instance;
    QString libRoot;
    QMultiHash<QString, MetaClass*> libHash;

    //sections parsers from Dom elements
    void loadClasses(QDomElement* root, const QString& libName, const QString& libPath);

protected:
    explicit LibLoader(QObject* parent = 0);

signals:
    void warning(QString msg) const;

};

#endif // LIBLOADER_H
